﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MYSMRM.Manager.Base;
using MYSMRM.Manager.Interface;
using MYSMRM.Model;
using Spring.Transaction.Interceptor;
using System.Data;
using MYSMRM.Dao.Implement;
using MYSMRM.Dao.Interface;

namespace MYSMRM.Manager.Implement
{
    public class QSTopicManager : ManagerBase<QSTopic>, IQSTopicManager
    {
        //public IQSOptionManager OptionManager { get; set; }
        public IQSQuestionDao Question { get; set; }

        public QSTopicManager()
        {
            this.CurrentDao = new QSTopicDao();
            Question = new QSQuestionDao();
        }

        public IList<QSTopic> LoadAllByPage(out long total, int id, int page, int rows, string order, string sort)
        {
            return ((IQSTopicDao)(this.CurrentDao))
                .LoadAllByPage(out total, id, page, rows, order, sort).ToList();
        }

        public IList<QSTopic> LoadAllEnable(int id)
        {
            return ((IQSTopicDao)(this.CurrentDao)).LoadAllEnable(id).ToList();
        }

        [Transaction]
        public void Save(QSTopic t, List<QSQuestion> lo)
        {
            base.Save(t);
            foreach (QSQuestion o in lo)
            {
                Question.Save(o);
            }
        }

        [Transaction]
        public void Save(QSTopic t, DataTable dto)
        {
            List<QSQuestion> lo = MYSMRM.Common.DataTable2Object.ConvertToList<QSQuestion>(dto);
            Save(t, lo);
        }

        [Transaction]
        public void Update(QSTopic t, List<QSQuestion> lo)
        {
            base.Update(t);
            Question.DeleteQuestionsByTopicID(t.ID);
            foreach (QSQuestion o in lo)
            {
                Question.Save(o);
            }
        }

        [Transaction]
        public void Update(QSTopic t, DataTable dto)
        {
            List<QSQuestion> lo = MYSMRM.Common.DataTable2Object.ConvertToList<QSQuestion>(dto);
            Update(t, lo);
        }
    }
}
